package kr.or.kosta.otr.persistence.message;


import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.annotation.Resource;

import kr.or.kosta.otr.vo.MessageVO;

import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;

@Repository("MessageDao")

public class MessageDaoImpl implements MessageDao{
	@Resource(name="sqlMapClient")
	private SqlMapClient sqlMapClient;
	
	@Override
	public void writeMessage(MessageVO vo) throws SQLException {
		sqlMapClient.insert("Message.writeMessage", vo);
	}

	@Override
	public void deleteMessage(int messageId) throws SQLException {
		sqlMapClient.delete("Message.deleteMessage", messageId);
	}

	@Override
	public MessageVO getOneMessage(int messageId) throws SQLException {
		return (MessageVO) sqlMapClient.queryForObject("Message.getOneMessage", messageId);
	}

	@Override
	public int getMessageCount(String userId) throws SQLException {
		return (int) sqlMapClient.queryForObject("Message.getMessageCount", userId);
	}

	@Override
	public ArrayList<MessageVO> getAllMessage(String userId) throws SQLException {
		return (ArrayList<MessageVO>) sqlMapClient.queryForList("Message.getAllMessage",userId);
	}

	@Override
	public void checkMessage(HashMap<String, Object> map) throws SQLException {
		// TODO Auto-generated method stub
		sqlMapClient.update("Message.checkMessage",map);
	}

	@Override
	public ArrayList<MessageVO> getAllSendMessage(String userId)
			throws SQLException {
		// TODO Auto-generated method stub
		return (ArrayList<MessageVO>) sqlMapClient.queryForList("Message.getAllSendMessage",userId);
	}

	@Override
	public ArrayList<MessageVO> getAllMessagePage(HashMap<String, Object> map)
			throws SQLException {
		// TODO Auto-generated method stub
		return (ArrayList<MessageVO>) sqlMapClient.queryForList("Message.getAllMessagePage",map);
	}

	@Override
	public int getAllMessageTotal(String userId) throws SQLException {
		// TODO Auto-generated method stub
		return (int) sqlMapClient.queryForObject("Message.getAllMessageTotal",userId);
	}
}
